

{% extends "cmdb/index.html" %}
{% block title %}服务器列表{% endblock %}

{% block breadcrumb  %}
    <ul class="breadcrumb">
                            <li>
                                <i class="ace-icon fa fa-home home-icon"></i>
                                <a href="#">Home</a>
                            </li>
                            <li>
                                <i class="ace-icon fa fa-home home-icon"></i>
                                <a href="#">saltstack</a>
                            </li>
                            <li class="active">salt常用操作</li>
                        </ul><!-- /.breadcrumb -->
{% endblock %}
{% block page-header %}
<div class="page-header">
    <h1>
        Dashboard
        <small>
            <i class="ace-icon fa fa-angle-double-right"></i>
        saltstack &amp; salt常用操作
        </small>
        </h1>
</div><!-- /.page-header -->
{% endblock %}

{% block content %}
{#    <form    class="form-inline" role="form" method="POST">#}
{#  <input type="hidden" name="csrfmiddlewaretoken" value="{{csrf_token}}">#}
{#  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#}
{#  <button id="serach_btn" type="submit" class="btn btn-default" >更新maste_key到本地数据库</button>#}
{#<button id="serach_btn" type="submit" class="btn btn-default" onclick="history.go(-1)" >返回</button>#}
{#</form>#}
    <div id="mytable">
     <table class="table table-striped" id="gridtable" width="100%" border="0.5">
        <thead>
        <tr>
            <th><input type="checkbox" name="check" id="all"/> </th>
            <th>minion_id</th>
            <th>Result</th>
        </tr>
        </thead>
{#     get_state_display 显示choices 的选项#}
        {% for i in accept_keys  %}
            <tr>
            <td><input   type="checkbox" name="check_box" value="{{ i }}" /> </td>
            <td class="success" >{{ i }}</td>


            <td></td>
            </tr>

        {% endfor %}


    </table>

   </div>
{% endblock %}
{% block scripts %}
    <script type="text/javascript">
    function ajax_get(url,sid,option,isresult){
    $.ajax({
            type: "POST",
            url:url,
           data: {serverid:sid,csrfmiddlewaretoken:"{{csrf_token}}",option:option},
            dataType: "json",
        async:false,
           beforeSend:function(XMLHttpRequest){
          $("#loading").html("<img src='/static/images/loading-1.gif' />"); //在后台返回success之前显示loading图标
     	},
            timeout:360,
            success: function(ret){
                $("#loading").empty(); //ajax返回成功，清除loading图标
                if(isresult==0){         //判断是否添加到表格
                    $("#mytable").find("tr").each(function() {
                    var tdArr = $(this).children();
                    selectid=tdArr.eq(1).html(); //判断ID是否相同,相同则自动修改 td result的显示
                    if(sid==selectid){
                        tdArr.eq(3).html(ret.msg);}
                    });

                }else {
                    alert(ret.msg);
                }
                var url="{% url 'key_list' %}?&r="+Math.random();
                window.location.href=url;
            },
                error: function (msg) {
                    alert("Connection error");
                    return  false;
                     }
    });
}

    function salt_key_del(minion_id){
            var url="{% url 'key_list' %}";
            var serverid=minion_id;
            var option="key_del";
            ajax_get(url,serverid,option,0)
    }


    function salt_key_accept(minion_id){
            var url="{% url 'key_list' %}";
            var serverid=minion_id;
            var option="accept_key";
            ajax_get(url,serverid,option,0)
    }

    $(document).ready(function() {
            $("#all").click(function(){
                if(this.checked){
                    $("[name=check_box]:checkbox").prop("checked", true);
                }else{
                    $("[name=check_box]:checkbox").removeAttr("checked");}
     });




    })
</script>


{% endblock %}
